﻿/// <reference path="jQuery/jquery.js" />

function submitCards(address) {
	var keys = jQuery.jStorage.index();

	var $form = jQuery("#postCards");
	$form.children().remove();
	if (address) {
		$form.attr("action", address);
	}

	for (var key in keys) {
		var realKey = keys[key];
		if (realKey.indexOf("fc_") == 0) {
			createNewFormElement($form, realKey);
		}
	}

	$form.submit();
}

function createNewFormElement($inputForm, key) {
	var card = jQuery.jStorage.get(key);

	if (card) {

		var index = jQuery("<input type='hidden' name='index' >").val(key);
		var word = jQuery("<input type='hidden' name='index' >").attr("name", "[" + key + "].word").val(card["w"]);
		var pronunciation = jQuery("<input type='hidden'>").attr("name", "[" + key + "].pronunciation").val(card["p"]);
		var meaning = jQuery("<input type='hidden'>").attr("name", "[" + key + "].meaning").val(card["m"]);
		var example = jQuery("<input type='hidden'>").attr("name", "[" + key + "].example").val(card["e"]);
		var translation = jQuery("<input type='hidden'>").attr("name", "[" + key + "].translation").val(card["t"]);

		$inputForm.append(index);
		$inputForm.append(word);
		$inputForm.append(pronunciation);
		$inputForm.append(meaning);
		$inputForm.append(example);
		$inputForm.append(translation);
	}
}

